package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertEngineFamilyDO;
import cqrtplm.service.RtCertEngineFamilyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(tags = "认证-发动机系族")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/enginefamily/" + "v1")
public class RtCertEngineFamilyController {

    @Resource
    private RtCertEngineFamilyService rtCertEngineFamilyService;

    @PostMapping("/list")
    @ApiOperation("获取发动机系族列表")
    public ResponseResult list(@RequestBody RtCertEngineFamilyDO rtCertEngineFamily) {
        List<RtCertEngineFamilyDO> list = rtCertEngineFamilyService.selectRtCertEngineFamilyList(rtCertEngineFamily);
        return ResponseResult.success(list);
    }

    @PostMapping("/pagelist")
    @ApiOperation("分页获取发动机系族列表")
    public ResponseResult<PageInfo<RtCertEngineFamilyDO>> pagelist(
            @RequestBody RtCertEngineFamilyDO rtCertEngineFamily,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertEngineFamilyDO> list = rtCertEngineFamilyService.selectRtCertEngineFamilyList(rtCertEngineFamily);
        return ResponseResult.success(new PageInfo<>(list));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取发动机系族详情")
    public ResponseResult getById(@PathVariable String id) {
        return ResponseResult.success(rtCertEngineFamilyService.selectRtCertEngineFamilyById(id));
    }

    @PostMapping("/add")
    @ApiOperation("新增发动机系族")
    public ResponseResult add(@RequestBody RtCertEngineFamilyDO rtCertEngineFamily) {
        return ResponseResult.success(rtCertEngineFamilyService.insertRtCertEngineFamily(rtCertEngineFamily));
    }

    @PostMapping("/edit")
    @ApiOperation("修改发动机系族")
    public ResponseResult edit(@RequestBody RtCertEngineFamilyDO rtCertEngineFamily) {
        return ResponseResult.success(rtCertEngineFamilyService.updateRtCertEngineFamily(rtCertEngineFamily));
    }

    @DeleteMapping("/del")
    @ApiOperation("删除发动机系族")
    public ResponseResult delete(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertEngineFamilyService.deleteRtCertEngineFamilyByIds(ids));
    }
}